﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GLSimulationControl
{
    public partial class ToolDirection : UserControl
    {
        [Browsable(true),DisplayName("Brush")]
        public Pen ToolPen{get;set;}

        [Browsable( true ), DisplayName( "Drawing margin" ),DefaultValue(10)]
        public int DrawingMargin{ get; set; }

        private double _directionX;
        private double _directionY;

        public double DirectionX
        {
            get
            {
                return this._directionX;
            }
            set
            {
                this._directionX = value;
                this.xDirectionLabel.Text = this._directionX.ToString();
                this.Refresh();
            }
        }

        public double DirectionY
        {
            get
            {
                return this._directionY;
            }
            set
            {
                this._directionY = value;
                this.yDirectionLabel.Text = this._directionY.ToString();
                this.Refresh();
            }
        }

        public ToolDirection()
        {
            InitializeComponent();
            this.ToolPen = Pens.Black;
            this.DirectionX = 0.5;
            this.DirectionY = -0.5;
        }

        private void ToolDirection_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            int minDim = Math.Min( this.Width, this.Height );
            int size = minDim - 2*DrawingMargin;
            g.DrawEllipse( Pens.Black, DrawingMargin, DrawingMargin, size, size );
            g.DrawLine( Pens.Black, this.DrawingMargin + size/2 ,this.DrawingMargin , DrawingMargin + size/2, DrawingMargin + size);
            g.DrawLine( Pens.Black, this.DrawingMargin, this.DrawingMargin + size / 2, DrawingMargin + size, this.DrawingMargin + size / 2 );

            int x1 = this.DrawingMargin + size / 2;
            int y1 = this.DrawingMargin + size / 2;
            int x2 = this.DrawingMargin + size / 2 + (int)(size * this.DirectionX);
            int y2 =  this.DrawingMargin + size / 2 + (int)(size * this.DirectionY);
            g.DrawLine( Pens.Red, x1,y1,x2,y2 );
        }
    }
}
